Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
child-process-promise
Advanced tools
Simple wrapper around the "child_process" module that makes use of promises
The 'child-process-promise' npm package is a utility that provides a promise-based interface for Node.js's child_process module. It allows you to execute shell commands and spawn new processes with the added benefit of using promises for better asynchronous control.
exec
The 'exec' function allows you to run a shell command and returns a promise that resolves with the command's output. This is useful for running simple shell commands and capturing their output.
const { exec } = require('child-process-promise');
exec('ls -la')
.then(result => {
console.log('stdout:', result.stdout);
console.log('stderr:', result.stderr);
})
.catch(err => {
console.error('ERROR:', err);
});
spawn
The 'spawn' function allows you to start a new process using a given command and arguments. It returns a promise that resolves when the process completes. This is useful for more complex scenarios where you need to interact with the process's input/output streams.
const { spawn } = require('child-process-promise');
const child = spawn('ls', ['-la']);
child.childProcess.stdout.on('data', data => {
console.log('stdout:', data.toString());
});
child.childProcess.stderr.on('data', data => {
console.error('stderr:', data.toString());
});
child.then(() => {
console.log('Process completed');
}).catch(err => {
console.error('ERROR:', err);
});
Execa is a modern alternative to child_process that provides a promise-based interface for executing shell commands. It offers more features and better defaults compared to child-process-promise, such as improved error handling and support for streaming output.
Promisify-child-process is another package that wraps Node.js's child_process module with promises. It provides a similar interface to child-process-promise but focuses on being a lightweight and minimalistic solution.
Node-cmd is a simple package for executing shell commands in Node.js. It provides a callback-based interface but can be easily used with promises using utilities like util.promisify. It is less feature-rich compared to child-process-promise but can be a good choice for simpler use cases.
Simple wrapper around the child_process
module that makes use of promises
npm install child-process-promise --save
var exec = require('child-process-promise').exec;
exec('echo hello')
.then(function (result) {
var stdout = result.stdout;
var stderr = result.stderr;
console.log('stdout: ', stdout);
console.log('stderr: ', stderr);
})
.fail(function (err) {
console.error('ERROR: ', err);
})
.progress(function (childProcess) {
console.log('childProcess.pid: ', childProcess.pid);
});
var spawn = require('child-process-promise').spawn;
spawn('echo', ['hello'])
.progress(function (childProcess) {
console.log('[spawn] childProcess.pid: ', childProcess.pid);
childProcess.stdout.on('data', function (data) {
console.log('[spawn] stdout: ', data.toString());
});
childProcess.stderr.on('data', function (data) {
console.log('[spawn] stderr: ', data.toString());
});
})
.then(function () {
console.log('[spawn] done!');
})
.fail(function (err) {
console.error('[spawn] ERROR: ', err);
});
Type: Array
Default: []
Pass an additional capture
option to buffer the result of stdout
and/or stderr
var spawn = require('child-process-promise').spawn;
spawn('echo', ['hello'], { capture: [ 'stdout', 'stderr' ]})
.then(function (result) {
console.log('[spawn] stdout: ', result.stdout.toString());
})
.fail(function (err) {
console.error('[spawn] stderr: ', err.stderr);
});
FAQs
Simple wrapper around the "child_process" module that makes use of promises
The npm package child-process-promise receives a total of 368,402 weekly downloads. As such, child-process-promise popularity was classified as popular.
We found that child-process-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.